﻿namespace PagedList
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class PagedList<T> : BasePagedList<T>
    {
        public PagedList(IEnumerable<T> superset, int index, int pageSize) : base(index, pageSize, (superset == null) ? 0 : superset.Count<T>())
        {
            if ((superset != null) && (base.TotalItemCount > 0))
            {
                base.Subset.AddRange((index == 0) ? superset.Skip<T>(0).Take<T>(pageSize).ToList<T>() : superset.Skip<T>((index * pageSize)).Take<T>(pageSize).ToList<T>());
            }
        }

        public PagedList(IQueryable<T> superset, int index, int pageSize) : base(index, pageSize, (superset == null) ? 0 : superset.Count<T>())
        {
            if ((superset != null) && (base.TotalItemCount > 0))
            {
                base.Subset.AddRange((index == 0) ? superset.Skip<T>(0).Take<T>(pageSize).ToList<T>() : superset.Skip<T>((index * pageSize)).Take<T>(pageSize).ToList<T>());
            }
        }
    }
}

